package com.hz.copyingsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hz.common.utils.PageUtils;
import com.hz.common.utils.Query;
import com.hz.copyingsystem.dao.HzFixedInformationDicDao;
import com.hz.copyingsystem.entity.FixedInformationDicEntity;
import com.hz.copyingsystem.service.HzFixedInformationDicService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("hzFixedInformationDicService")
public class HzFixedInformationDicServiceImpl extends ServiceImpl<HzFixedInformationDicDao, FixedInformationDicEntity> implements HzFixedInformationDicService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<FixedInformationDicEntity> page = this.page(
                new Query<FixedInformationDicEntity>().getPage(params),
                new QueryWrapper<FixedInformationDicEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<FixedInformationDicEntity> queryYears(Integer curPage, Integer pageSize, String fixedInformationName) {
        curPage = (curPage-1) * pageSize;
        return this.baseMapper.queryYears(curPage, pageSize, fixedInformationName);
    }

    /**
     * 获取总记录数
     * @param fixedInformationName
     * @return
     */
    @Override
    public Integer queryFixedInformationDicsNum(String fixedInformationName) {
        return this.baseMapper.queryFixedInformationDicsNum(fixedInformationName);
    }

    /**
     * 根据yid、sid、cid分别查出年代、书体、书家顺序的字典信息list
     * @param yid
     * @param sid
     * @param cid
     * @return
     */
    @Override
    public List<FixedInformationDicEntity> findByIds(long yid, long sid, long cid) {
        return this.baseMapper.findByIds(yid, sid, cid);
    }

    @Override
    public List<FixedInformationDicEntity> queryByName(String informationName) {
        return this.baseMapper.selectList(
                new QueryWrapper<FixedInformationDicEntity>().eq("fixed_information_name", informationName)
                        .orderByAsc("iorder"));
    }

    @Override
    public List<FixedInformationDicEntity> queryByNameAndContent(String name, String content) {
        return this.baseMapper.selectList(new QueryWrapper<FixedInformationDicEntity>().eq("fixed_information_name", name).eq("fixed_information_content",content));
    }

    @Override
    public List<FixedInformationDicEntity> queryByNameAndRemarks(String name, String remarks) {
        return this.baseMapper.selectList(new QueryWrapper<FixedInformationDicEntity>().eq("fixed_information_name", name).eq("remarks",remarks));
    }

    @Override
    public Integer queryByNameAndRemarksNum(String fixedInformationName, String remarks) {
        return this.baseMapper.selectList(
                new QueryWrapper<FixedInformationDicEntity>().eq("fixed_information_name", fixedInformationName)
                        .eq("remarks", remarks)).size();
    }

}